<template>
  <div>页面2</div>
  <div>接收到信息：{{recordMes}}</div>
</template>

<script>
export default {
  data(){
    return{
      broadcastChannel: null,
      recordMes: ''
    }
  },
  // 在Vue组件中
  mounted() {
    this.broadcastChannel = new BroadcastChannel('my_channel');
    this.broadcastChannel.onmessage = this.handleBroadcastMessage;
  },
  beforeUnmount() {
    this.broadcastChannel.close();
    this.broadcastChannel = null
  },
  methods: {
    handleBroadcastMessage(event) {
      console.log('收到广播消息:', event.data);
      this.recordMes = event.data
    }
  }
}
</script>